
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN

#include <windows.h>
#include <tchar.h>

#include "GLWindow.h"
#include "Example.h"


int WINAPI WinMain(HINSTANCE hInstance,
				   HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine,
				   int nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	GLWindow oMainWindow(hInstance);
	Example oExample;

	oMainWindow.attachApp(&oExample);

	//Attempt to create the window
	if (!oMainWindow.create())
	{
		MessageBox(NULL, _T("Unable to create the OpenGL Window"), _T("An error occurred"), MB_ICONERROR | MB_OK);
		oMainWindow.destroy();
		return 1;
	}

	if (!oExample.init()) //Initialize our example
	{
		MessageBox(NULL, _T("Could not initialize the application"), _T("An error occurred"), MB_ICONERROR | MB_OK);
		oExample.destroy();
		return 1;
	}

	//This is the mainloop, we render frames until isRunning returns false
	while(oMainWindow.isRunning())
	{
		//Process any window events
		oMainWindow.processEvents();

		//We get the time that passed since the last frame
		float elapsedTime = oMainWindow.getElapsedSeconds();

		oExample.update(elapsedTime); //Do any pre-rendering logic
		oExample.render(); //Render the scene
		
		oMainWindow.swapBuffers();
	}

	oExample.shutdown(); //Free any resources
	
	oMainWindow.destroy(); //Destroy the program window
	return 0; //Return success
}
